package smartlifev30.com.sdk.util;

import java.util.Locale;
import java.util.concurrent.atomic.AtomicInteger;

/**
 *
 * @author tys
 * @date 2018/8/12
 */

public class MsgIdBuilder {
    private static final String PREF = "And";
    private static final AtomicInteger c = new AtomicInteger(1);
    private static final String POOL = "ABCDEFGHIJKLMNOPQRSTUVWXVZabcdefghijklmnopqrstuvwxvz";

    synchronized public static String build() {
        if (c.get() > 999) {
            c.set(1);
        }
        String num = String.format(Locale.getDefault(), "%03d", c.getAndIncrement());
        return String.format(Locale.getDefault(), "%s%s%s%s", PREF, roundStr(2), "-", num);
    }

    private static String roundStr(int len) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, index; i < len; i++) {
            index = (int) (Math.random() * POOL.length());
            sb.append(POOL.charAt(index));
        }
        return sb.toString();
    }

}
